<?php

namespace app\api\controller;

use app\admin\model\Activity;
use app\admin\model\Adv;
use app\admin\model\System;
use app\admin\model\SystemMessage;
use app\common\controller\Api;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }

    //广告图
    public function adv()
    {
        $list = Adv::order('weigh desc')->select();
        $this->success('请求成功',$list);
    }

    //系统消息
    public function systemmessage()
    {
        $list = SystemMessage::order('weigh desc')->select();
        $this->success('请求成功',$list);
    }

    //今日活动
    public function activity()
    {
        $list = Activity::order('weigh desc')->select();
        $this->success('请求成功',$list);
    }

    //系统下载
    public function system()
    {
        $pid = input('pid',0);
        $where = [];
        if ($pid){
            $where['pid'] = $pid;
        } else {
            $where['pid'] = 0;
            $where['level'] = 1;
        }

        $list = System::where($where)->select();
        $this->success('请求成功',$list);
    }

    //获取系统下载的展示信息
    public function showSystemInfo()
    {
        $id = input('id',0);

        $detail = System::get($id);
        if ($detail->url){
            $queryString = parse_url($detail->url, PHP_URL_QUERY);
            parse_str($queryString, $params);
            $detail->password = $params['pwd'];
        }


        $this->success('请求成功',$detail);
    }
}
